package action;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import service.service_search.Service_Search;
import tools.Convert;
import tools.InterfaceDepthIceList;
import tools.InterfaceEvaluateList;
import tools.PageBeanPlus;
import entitybean.l_sequence.EntityBeanL_Sequence;
import entitybean.oc_depthlist_ice.EntityBeanOc_Depthlist_Ice;
import entitybean.oc_evaluate.EntityBeanOc_Evaluate;
import entitybean.oc_news.EntityBeanOc_News;
import form.DepthIceForm;
import form.EvaluateForm;

public class Action_Oc_Evaluate extends DispatchAction{
	private Service_Admin service_admin;
    private Service_Public service_public;
 	private Service_Search service_search;
	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin service_admin) {
		this.service_admin = service_admin;
	}

	public Service_Public getService_public() {
		return service_public;
	}

	public void setService_public(Service_Public service_public) {
		this.service_public = service_public;
	}

	public Service_Search getService_search() {
		return service_search;
	}

	public void setService_search(Service_Search service_search) {
		this.service_search = service_search;
	}

	public ActionForward admin_init_oc_evaluate_show(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		EvaluateForm goodform = (EvaluateForm) form;
		goodform.setCurrentpage("1");

		String sql = "select id,news_title,update_time,user_id  from oc_evaluate where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(goodform.getRowcountperpage()), Integer
						.valueOf(goodform.getCurrentpage()),
				"loadrichtext()");
		InterfaceEvaluateList interfaceforresultsettolist = new InterfaceEvaluateList();
		List<EntityBeanOc_Evaluate> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);
		request.setAttribute("list", list);
		request.setAttribute("newslistform", goodform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_load_oc_evaluate(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return null;
	}

	public ActionForward admin_add_oc_evaluate(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return mapping.findForward("success");
	}

	public ActionForward admin_insert_oc_evaluate(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		EvaluateForm actionForm = (EvaluateForm) form;
		String news_title=actionForm.getNews_title();
		String news_clob=actionForm.getNews_clob();
		EntityBeanOc_Evaluate link=new EntityBeanOc_Evaluate();
		link.setNews_title(news_title);
		link.setNews_clob_string(news_clob);
		link.setUpdate_time(new Date());
		link.setUser_id(1);
		link.setDel("OFF");
		Integer i=0;
		EntityBeanL_Sequence entity=new EntityBeanL_Sequence();
		entity=this.service_public.Find_L_Sequence_By_seq_Name("SEQ_OC_DEPTH_ICE");
		i=entity.getSeq_Value()+1;
		entity.setSeq_Value(i);
		link.setId(i);
		this.service_public.Update_L_Sequence(entity);
		this.service_admin.Insert_Oc_Evaluate(link);
		EvaluateForm goodform = (EvaluateForm) form;
		goodform.setCurrentpage("1");

		String sql = "select id,news_title,update_time,user_id  from oc_evaluate where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(goodform.getRowcountperpage()), Integer
						.valueOf(goodform.getCurrentpage()),
				"loadrichtext()");
		InterfaceEvaluateList interfaceforresultsettolist = new InterfaceEvaluateList();
		List<EntityBeanOc_Evaluate> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);
		request.setAttribute("list", list);
		request.setAttribute("newslistform", goodform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_delete_oc_evaluate(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		EvaluateForm goodform = (EvaluateForm) form;
		String id = goodform.getId();
		id = this.cut_tail(id);
		this.service_admin.Delete_Oc_Evaluate(id);

		String sql = "select id,news_title,update_time,user_id  from oc_evaluate where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(goodform.getRowcountperpage()), Integer
						.valueOf(goodform.getCurrentpage()),
				"loadrichtext()");
		InterfaceEvaluateList interfaceforresultsettolist = new InterfaceEvaluateList();
		List<EntityBeanOc_Evaluate> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);
		request.setAttribute("list", list);
		request.setAttribute("newslistform", goodform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}
	public ActionForward admin_update_init_oc_evaluate(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		EvaluateForm actionForm = (EvaluateForm) form;
		String id=actionForm.getId();	
		EntityBeanOc_Evaluate e=this.service_admin.Find_EntityBeanOc_Evaluate(Integer.valueOf(id));
		Convert c = new Convert();
		e.setNews_clob_string(c.ConvertClobToString(e.getNews_clob()));
		request.setAttribute("e", e);
		return mapping.findForward("success");
	}
	public ActionForward admin_update_oc_evaluate(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		EvaluateForm actionForm = (EvaluateForm) form;
		String id=actionForm.getId();
		String news_title=actionForm.getNews_title();
		String news_clob=actionForm.getNews_clob();
		EntityBeanOc_Evaluate link=new EntityBeanOc_Evaluate();
		link.setNews_title(news_title);
		link.setNews_clob_string(news_clob);
		link.setUpdate_time(new Date());
		link.setUser_id(1);
		link.setDel("OFF");
		link.setId(Integer.valueOf(id));
		id = this.cut_tail(id);
		this.service_admin.Delete_Oc_Evaluate(link);
		this.service_admin.Insert_Oc_Evaluate(link);
		EvaluateForm goodform = (EvaluateForm) form;
		goodform.setCurrentpage("1");

		String sql = "select id,news_title,update_time,user_id  from oc_evaluate where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(goodform.getRowcountperpage()), Integer
						.valueOf(goodform.getCurrentpage()),
				"loadrichtext()");
		InterfaceEvaluateList interfaceforresultsettolist = new InterfaceEvaluateList();
		List<EntityBeanOc_Evaluate> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);
		request.setAttribute("list", list);
		request.setAttribute("newslistform", goodform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_search_oc_evaluate(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		EvaluateForm goodform = (EvaluateForm) form;
		String sql = "select id,news_title,update_time,user_id  from oc_evaluate where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(goodform.getRowcountperpage()), Integer
						.valueOf(goodform.getCurrentpage()),
				"loadrichtext()");
		InterfaceEvaluateList interfaceforresultsettolist = new InterfaceEvaluateList();
		List<EntityBeanOc_Evaluate> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);
		request.setAttribute("list", list);
		request.setAttribute("newslistform", goodform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	private String cut_tail(String str) {
		String cut = str;
		if (str.endsWith(",")) {
			cut = cut.substring(0, cut.length() - 1);
		}
		return cut;
	}
}
